classdef historyList < handle
    properties
        hList
        nLen
        currentIndex
    end
    
    methods
        function obj = historyList(node)
            obj.hList = {node};
            obj.nLen = length(obj.hList);
            obj.currentIndex = 1;
        end
        
        function obj = addNode(obj, node)
            obj.hList = [obj.hList, {node}];
            obj.nLen = length(obj.hList);
            obj.currentIndex = obj.nLen;
        end
        
        function node = currentNode(obj)
            node = obj.hList{obj.currentIndex};
        end
        
        function node = moveForward(obj)
            if obj.currentIndex < obj.nLen
                obj.currentIndex = obj.currentIndex+1;
                node = obj.hList{obj.currentIndex};
            else
                warning('Already at the last node.');
                node = [];
            end
        end
        
        function node = moveBackward(obj)
            if obj.currentIndex > 1
                obj.currentIndex = obj.currentIndex-1;
                node = obj.hList{obj.currentIndex};
            else
                warning('Already at the first node.');
                node = [];
            end
        end
        
        function disp(obj)
            disp(obj.hList);
        end
    end
end

